package com.hengshan.service.impl;

import com.hengshan.common.utils.SecurityUtils;
import org.springframework.stereotype.Service;

import java.util.List;

@Service("permission")
public class PermissionService {

    // 所有权限标识
    private static final String ALL_PERMISSION = "*:*:*";
    // 管理员角色权限标识
    private static final String SUPER_ADMIN = "admin";

    /**
     * 判断用户是否有权限
     *
     * @param permission 权限
     * @return boolean 用户是否具备某权限
     */
    public boolean hasPermission(String permission) {
        List<String> permissions = SecurityUtils.getLoginUser().getPermissions();
        return permissions.contains(ALL_PERMISSION) || permissions.contains(permission);
    }
}
